package com.gragra.structures.mainDatatypes;
import java.util.Arrays;
import com.gragra.structures.SentenceStructure;
import com.gragra.util.StringToInt;
/**
 * simple implementation of the sentencestructure interface, uses StringToInt to
 * code the words
 * @author Christoph Teichmann
 * @version 0.1
 */
public class SimpleSentenceStructure implements SentenceStructure
{
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		StringBuilder builder = new StringBuilder();
		builder.append("SimpleSentenceStructure [codes=");
		builder.append(Arrays.toString(codes));
		builder.append("]");
		return builder.toString();
	}
	/**
	 * contains the numerical codes for the words in this sentences assigned by
	 * the StringToInt class
	 */
	private final int[] codes;
	/**
	 * returns creates the structure with the given words
	 * @param words
	 */
	public SimpleSentenceStructure(final String[] words)
	{
		codes = new int[words.length];
		for (int i = 0; i < words.length; i++)
		{codes[i] = StringToInt.ensure(words[i]);}
	}
	/* (non-Javadoc)
	 * @see structures.SentenceStructure#size()
	 */
	@Override
	public int size()
	{return codes.length;}
	/* (non-Javadoc)
	 * @see structures.SentenceStructure#getWord(int)
	 */
	@Override
	public Integer getWord(final int i)
	{return codes[i];}
}